using System;
using System.Collections.Generic;
using System.Text;

using SlimDX;

using miciv;
using miciv.Rendering;
using micivRenderers.Renderers;

namespace micivRenderers
{
    public class Module : IModule
    {
        protected CoreContext m_coreContext;
        protected NullRenderer m_rendererNull;
        protected DiffuseRenderer m_rendererDiffuse;
        protected TextureDiffuseRenderer m_rendererTextureDiffuse;
        protected MaskTextureDiffuseRenderer m_rendererMaskTextureDiffuse;

        public Module(CoreContext _coreContext)
        {
            this.m_coreContext = _coreContext;
        }

        #region IModule Membres

        public bool Load()
        {
            int vertexMax = 0;
            int indexMax = 0;

            CoreManager coreManager = this.m_coreContext.CoreManager;
            RendererManager rendererManager = this.m_coreContext.GetData<RendererManager>("RendererManager");

            this.m_rendererNull = new NullRenderer();
            this.m_rendererNull.Initialize(this.m_coreContext);
            rendererManager.Add("NullRenderer", this.m_rendererNull);

            this.m_rendererDiffuse = new DiffuseRenderer();
            vertexMax = 1000; // max chars
            vertexMax *= (4 + 2);  // 4 vertex per char quad + vertex per char link
            indexMax = vertexMax * 4;
            this.m_rendererDiffuse.Initialize(this.m_coreContext, vertexMax, indexMax);
            rendererManager.Add("DiffuseRenderer", this.m_rendererDiffuse);

            this.m_rendererTextureDiffuse = new TextureDiffuseRenderer();
            vertexMax = 1000; // max chars
            vertexMax *= (4 + 2);  // 4 vertex per char quad + vertex per char link
            indexMax = vertexMax * 4;
            this.m_rendererTextureDiffuse.Initialize(this.m_coreContext, vertexMax, indexMax);
            rendererManager.Add("TextureDiffuseRenderer", this.m_rendererTextureDiffuse);

            this.m_rendererMaskTextureDiffuse = new MaskTextureDiffuseRenderer();
            vertexMax = 200 * 200; // max map size
            vertexMax *= 4;  // 4 vertex per tile quad
            vertexMax *= 4;  // 4 elements per tile (average value) : tile itself, tile modifier, 2 units
            indexMax = vertexMax * 4;
            this.m_rendererMaskTextureDiffuse.Initialize(this.m_coreContext, vertexMax, indexMax);
            rendererManager.Add("MaskTextureDiffuseRenderer", this.m_rendererMaskTextureDiffuse);

            return true;
        }

        public void Unload()
        {
        }

        #endregion
    }
}
